package com.uzai.console.aop;

import com.uzai.common.result.ResponseCode;
import org.slf4j.MDC;

import java.io.Serializable;

/**
 *
 * @author liuqi
 * @date 2022年09月20日 12:04
 */
public class ResponseResultConsole implements Serializable {
    private Integer code;
    private String msg;
    private Object data;
    private Long time;
    private String traceId;

    public ResponseResultConsole() {
        this.code = ResponseCode.SUCCESS;
        this.time = System.currentTimeMillis();
        this.traceId = MDC.get("X-B3-TraceId");
    }

    public ResponseResultConsole(String msg) {
        this.code = ResponseCode.SUCCESS;
        this.time = System.currentTimeMillis();
        this.msg = msg;
        this.traceId = MDC.get("X-B3-TraceId");
    }

    public ResponseResultConsole(Integer code, String msg) {
        this.code = ResponseCode.SUCCESS;
        this.time = System.currentTimeMillis();
        this.code = code;
        this.msg = msg;
        this.traceId = MDC.get("X-B3-TraceId");
    }

    public ResponseResultConsole(Integer code, String msg, Object data) {
        this.code = ResponseCode.SUCCESS;
        this.time = System.currentTimeMillis();
        this.code = code;
        this.msg = msg;
        this.traceId = MDC.get("X-B3-TraceId");
        this.data = data;
    }

    public ResponseResultConsole(Integer code, String msg, Object data, Long time) {
        this.code = ResponseCode.SUCCESS;
        this.time = System.currentTimeMillis();
        this.code = code;
        this.msg = msg;
        this.traceId = MDC.get("X-B3-TraceId");
        this.data = data;
        this.time = time;
    }

    public static ResponseResultConsole success(String message) {
        return new ResponseResultConsole(ResponseCode.SUCCESS, message);
    }

    public static ResponseResultConsole error(String message) {
        return new ResponseResultConsole(ResponseCode.ERROR, message);
    }

    public Integer getCode() {
        return this.code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return this.data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Long getTime() {
        return this.time;
    }

    public void setTime(Long time) {
        this.time = time;
    }

    public String getTransId() {
        return traceId;
    }

    public void setTransId(String transId) {
        this.traceId = transId;
    }

    public String toString() {
        return "ResponseResult{code=" + this.code + ", msg='" + this.msg + '\'' + ", data=" + this.data + ", time=" + this.time + ", transId=" + this.traceId + '}';
    }
}
